//
//  QDNewMPItemsCycleTableViewCell.m
//  QDMetroClient
//
//  Created by YueWen on 2019/2/11.
//  Copyright © 2019 YueWen. All rights reserved.
//

#import "QDNewMPItemsCycleTableViewCell.h"
#import "QDItemButtonCollectionViewCell.h"
#import "QDMetroClient-Swift.h"

NSString *QDSDCycleAnimatedCellKey = @"QDSDCycleAnimatedCellKey";
NSString *QDSDCycleItemCellKey = @"QDSDCycleItemCellKey";


@interface QDNewMPItemsCycleTableViewCell()

/// 底部的遮罩视图
@property (nonatomic, strong, readwrite) UIImageView *shadowImageView;

@end


@implementation QDNewMPItemsCycleTableViewCell

@synthesize flowLayout = _flowLayout;

- (void)buildView {
    
    [super buildView];
 
    self.cycleView.infiniteLoop = false;
    self.cycleView.autoScroll = false;
    self.cycleView.pageEnable = false;
    self.cycleView.contentView.showsVerticalScrollIndicator = false;
    self.cycleView.contentView.showsHorizontalScrollIndicator = false;
    
    self.shadowImageView = UIImageView.new;
    self.shadowImageView.image = @"nav_shadow_bottom".ritl_image;
    [self.contentView addSubview:self.shadowImageView];
    
//    self.bottomLineView.backgroundColor = QDSMainPageBottomColor;
//    self.bottomLineHeight = 9;
    
    [self.shadowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.mas_equalTo(9);
        make.bottom.offset(0);
    }];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.contentView bringSubviewToFront:self.shadowImageView];
}

- (UIEdgeInsets)cycleContentInsets {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}



#pragma mark - <RITLSDCycleScrollViewDataSource>


- (NSDictionary<NSString *,Class> *)cycleViewAllRegisterCellClasses:(RITLSDCycleScrollView *)cycleView {
    
    return @{QDSDCycleAnimatedCellKey: QDMPItemAnimableButtonCollectionViewCell.class,
             QDSDCycleItemCellKey: QDMPItemButtonCollectionViewCell.class};
}



- (UICollectionViewLayout *)cycleScollViewcustomCollectionViewLayout:(RITLSDCycleScrollView *)cycleView {
    return self.flowLayout;
}



#pragma mark - FlowLayout

- (UICollectionViewFlowLayout *)flowLayout {
    if (!_flowLayout) {
        
        _flowLayout = ({
            
            CGFloat width = MIN((UIScreen.mainScreen.ritl_width - 7) / 4, 92);
            UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
            
            flowLayout.itemSize = @[@(width),isSmallerScreen() ? @67 : @71].ritl_size;
            flowLayout.sectionInset = UIEdgeInsetsMake(6, 3.5, 9, 3.5);
            flowLayout.minimumLineSpacing = 4;
            flowLayout.minimumInteritemSpacing = CGFLOAT_MIN;

            flowLayout;
        });
    }
    return _flowLayout;
}


- (void)setFlowLayout:(UICollectionViewFlowLayout *)flowLayout {
    
    _flowLayout = flowLayout;
    self.cycleView.contentView.collectionViewLayout = flowLayout;
}

@end
